package cn.hospital.util;

import cn.hospital.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;


/**
 * 配置拦截器信息
 *
 * @author PHP
 */
@Configuration
public class LoginInterceptorConfigurer implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //黑名单---拦截路径---必须登录才能访问
        List<String> patterns = new ArrayList<String>();
        patterns.add("/**");
        //白名单---在黑名单范围内，不需要登录可以访问
        List<String> excludePatterns = new ArrayList<String>();
        //样式文件
        excludePatterns.add("/common/**");
        excludePatterns.add("/css/**");
        excludePatterns.add("/images/**");
        excludePatterns.add("/js/**");
        excludePatterns.add("/json/**");
        excludePatterns.add("/jsplug/**");
        excludePatterns.add("/pageCss/**");
        excludePatterns.add("/pageJs/**");
        excludePatterns.add("/plugins/**");
        //一上来展示页面
        excludePatterns.add("/index.jsp");
        excludePatterns.add("/loginRegistered/exit");
        //登录
        excludePatterns.add("/page/LoginRegister/login.jsp");
        excludePatterns.add("/loginRegistered/findByUsernamePassword");
        //注册
        excludePatterns.add("/page/LoginRegister/registered.jsp");
        excludePatterns.add("/DropDownBoxQuery/findHospitalDempartment");
        excludePatterns.add("/DropDownBoxQuery/findRole");
        excludePatterns.add("/loginRegistered/findByUserPhone");
        excludePatterns.add("/loginRegistered/findByUserEmail");
        excludePatterns.add("/loginRegistered/addMeaningUser");

        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns(patterns)
                .excludePathPatterns(excludePatterns);

    }

}
